package com.xf.system.exception;
import com.alibaba.fastjson.JSONObject;

/**
 * @author xiefengf
 */
public class BusinessException extends RuntimeException {
    private ErrorCodeAndMessage error;
    private Object data;

    public BusinessException(ErrorCodeAndMessage error) {
        this.error = error;
    }

    public BusinessException(Integer errorCode, String errorMessage, String data) {
        this.error = ErrorCodeAndMessage.create(errorCode, errorMessage);
        this.data = data;
    }

    public BusinessException(Integer errorCode, String errorMessage) {
        this.error = ErrorCodeAndMessage.create(errorCode, errorMessage);
    }

    public BusinessException(ErrorCodeAndMessage error, Throwable cause, String data) {
        super(JSONObject.toJSONString(error), cause);
        this.data = data;
    }

    public ErrorCodeAndMessage getError() {
        return this.error;
    }

    public Object getData() {
        return this.data;
    }

    public void setError(final ErrorCodeAndMessage error) {
        this.error = error;
    }

    public void setData(final Object data) {
        this.data = data;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BusinessException)) {
            return false;
        } else {
            BusinessException other = (BusinessException)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$error = this.getError();
                Object other$error = other.getError();
                if (this$error == null) {
                    if (other$error != null) {
                        return false;
                    }
                } else if (!this$error.equals(other$error)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof BusinessException;
    }

    public int hashCode() {
        int result = 1;
        Object $error = this.getError();
        result = result * 59 + ($error == null ? 43 : $error.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "BusinessException(error=" + this.getError() + ", data=" + this.getData() + ")";
    }

    public BusinessException(final ErrorCodeAndMessage error, final Object data) {
        this.error = error;
        this.data = data;
    }
}
